#include <iostream>
#include "TCP_server.hpp"
#include "Protocol.hpp"
#include "NetCal.hpp"
#include <string>
#include <memory>



int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage:" << argv[0] << "+port";
        return 1;
    }
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<Cal> count = std::make_unique<Cal>();

    std::unique_ptr<Protocol> col = std::make_unique<Protocol>([&count](Request &req) -> Response
                                                               { return count->Execute(req); });

    std::unique_ptr<TcpServer> USEV = std::make_unique<TcpServer>(port,
                                                                  [&col](std::shared_ptr<Socket> ptr, InetAddr client)
                                                                  {
                                                                      col->GetRequest(ptr, client);
                                                                  });
    USEV->Run();                                                              
    return 0;
}